package com.ruoyi.web.controller.productionre;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.production.domain.SimpleProduction;
import com.ruoyi.production.domain.StromaReturn;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.PlugReturn;
import com.ruoyi.production.service.IPlugReturnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 穴盘退回Controller
 *
 * @author ruoyi
 * @date 2021-07-17
 */
@Api("穴盘退回")
@RestController
@RequestMapping("/production/plugre")
public class PlugReturnController extends BaseController
{
    @Autowired
    private IPlugReturnService plugReturnService;

    /**
     * 查询穴盘退回列表
     */
    @ApiOperation("查询穴盘退回列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:plugre:list')")
    @GetMapping("/list")
    public TableDataInfo list(PlugReturn plugReturn)
    {
        startPage();
        List<PlugReturn> list = plugReturnService.selectPlugReturnList(plugReturn);
        return getDataTable(list);
    }

    /**
     * 导出穴盘退回列表
     */
    @ApiOperation("导出穴盘退回列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:plugre:export')")
    @Log(title = "穴盘退回", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PlugReturn plugReturn)
    {
        List<PlugReturn> list=new ArrayList();
        //通过id来取
        Long a[]=plugReturn.getPlugReturnIds();
        for(int i=0;i<a.length;i++) {
            PlugReturn list1 = plugReturnService.selectPlugReturnById(a[i]);
            list.add(list1);
        }

        ExcelUtil<PlugReturn> util = new ExcelUtil<PlugReturn>(PlugReturn.class);
        return util.exportExcel(list, "穴盘退回数据");
    }

    /**
     * 获取穴盘退回详细信息
     */
    @ApiOperation("获取穴盘退回详细信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:plugre:query')")
    @GetMapping(value = "/{plugReturnId}")
    public AjaxResult getInfo(@PathVariable("plugReturnId") Long plugReturnId)
    {
        return AjaxResult.success(plugReturnService.selectPlugReturnById(plugReturnId));
    }

    /**
     * 新增穴盘退回
     */
    @ApiOperation("新增穴盘退回")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:plugre:add')")
    @Log(title = "穴盘退回", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlugReturn plugReturn)
    {
        return toAjax(plugReturnService.insertPlugReturn(plugReturn));
    }

    /**
     * 修改穴盘退回
     */
    @ApiOperation("修改穴盘退回")
    @ResponseBody
    @PreAuthorize("@ss.hasAnyPermi('production:plugre:edit,production:plugre:permit')")
    @Log(title = "穴盘退回", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlugReturn plugReturn)
    {
        return toAjax(plugReturnService.updatePlugReturn(plugReturn));
    }

    /**
     * 删除穴盘退回
     */
    @ApiOperation("删除穴盘退回")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:plugre:remove')")
    @Log(title = "穴盘退回", businessType = BusinessType.DELETE)
	@DeleteMapping("/{plugReturnIds}")
    public AjaxResult remove(@PathVariable Long[] plugReturnIds)
    {
        return toAjax(plugReturnService.deletePlugReturnByIds(plugReturnIds));
    }

    /**
     * 获取穴盘类型下拉框
     */
    @ApiOperation("获取穴盘类型下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:plugre:plugtype')")
    @GetMapping("/plugtype")
    public TableDataInfo getPlugType()
    {
        List<PlugReturn> list = plugReturnService.getPlugType();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (PlugReturn plugReturn:list) {
            Long id = plugReturn.getPlugTypeId();
            String name = plugReturn.getPlugType();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取用户下拉框
     */
    @ApiOperation("获取用户下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:plugre:username')")
    @GetMapping("/username")
    public TableDataInfo getUserName()
    {
        List<PlugReturn> list = plugReturnService.getUserName();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (PlugReturn plugReturn:list) {
            Long id = plugReturn.getUserId();
            String name = plugReturn.getUserName();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取品牌下拉框
     */
    @ApiOperation("获取品牌下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:plugre:brand')")
    @GetMapping("/brand/{plugTypeId}")
    public TableDataInfo getBrand(@PathVariable("plugTypeId") Long plugTypeId)
    {
        List<String> list = plugReturnService.getBrand(plugTypeId);
        return getDataTable(list);
    }

    /**
     * 获取公司下拉框
     */
    @ApiOperation("获取公司下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:plugre:origincompany')")
    @GetMapping("/origincompany/{plugTypeId}")
    public TableDataInfo getOriginCompany(@PathVariable("plugTypeId") Long plugTypeId)
    {
        List<String> list = plugReturnService.getOriginCompany(plugTypeId);
        return getDataTable(list);
    }
}
